package br.edu.ufcg.splab.techniques.reduction.functions.choice;

import br.edu.ufcg.splab.generator.TestCase;

public class LengthTestCases implements ChoiceFunction{
	private TestCase firstChoose;
	private TestCase secondChoose;
	
	public LengthTestCases(){
		firstChoose = new TestCase();
		secondChoose = new TestCase();
	}
	
	public void defineOrderChoice(TestCase tc1, TestCase tc2){
		if(tc1.getTestCase().size() == tc2.getTestCase().size()) {
		    //Random choice
		    if (Math.random() < 0.5) {
	            firstChoose = tc1;
	            secondChoose = tc2;
	        } else {
	            firstChoose = tc2;
	            secondChoose = tc1;
	        }
		}else {
		    //analyze the smaller test case first and the bigger second
			if(tc1.getTestCase().size() < tc2.getTestCase().size()) {
		    	firstChoose = tc1;
		    	secondChoose = tc2;
		    }else {
		    	firstChoose = tc2;
		    	secondChoose = tc1;
		    }
		}		
	}
	
	public TestCase firstChoice(){
		return firstChoose;
	}
	
	public TestCase secondChoice(){
		return secondChoose;
	}
	
	/**
     * Provide a string representation of the choice function to be written.
     * @return The string representation of the choice function.
     */
	public String getFunction(){
		return "Length";
	}
}
